package jin.si.com.web;

import java.util.Comparator;

/**
 * @description:
 * @ClassName MyComparator
 * @Author MT
 * @Date 2021/7/4 9:35
 **/
public class MyComparator implements Comparator {
    @Override
    public int compare(Object o1, Object o2) {
        Pig newPig= (Pig) o1;
        Pig oldPig= (Pig) o2;
        int result=0;

        result=newPig.getName().compareTo(oldPig.getName());
        if(result==0){
            result=newPig.getAge()-oldPig.getAge();
        }
        return result;
    }
}
